#ifndef INCLUDED_ParameterList
#define INCLUDED_ParameterList
/*
 * This parameter file is modeifed from SOCS system.
 */
#include "Flags.h"
#include "ShortReadUtil.h"
#include "ReadsFileParser.h"
#include "stdafx.h"
#include <string>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <limits>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
using namespace std;

class MappingOpts
{
public:
    MappingOpts(void);
    ~MappingOpts(void);
    void setDefaults(void);
    void clearOutputFileName(bool clear = true);
    unsigned int readLength;
    unsigned int anchorLength;
    string fullCommand;
    // I/O options
    bool bPrintSamHeader;             // Default is true
    bool bDiscardReadWithN;           // Default is true
    bool bIgnoreQS;                   // Default is false
    bool bPrintAlignments;            // Default is false
    bool bPrintUnMappedReads;         // Default is false
    bool bPrintRef;                   // Default is false
    bool bCanoicalOnly;               // Default is true
    bool bExcludeAmbiguousReads;      // Default is true
    bool bGetAllAlignments;           // Default is true, for anchor two end
    bool bGetAllDelAlignments;        // Default is false
    bool bGetIntronSeq;               // Default is false
    char outputDir[FILENAME_MAX];
    char outputFileN[FILENAME_MAX];
    char outputFormat[FILENAME_MAX];
    char unmappedFileN[FILENAME_MAX];
    char readsFileFormat[FILENAME_MAX];
    int subDiffThreshold;
    int MEMES;// Minimal Match on Either Side

    bool bUniqueMapOnly;
    int disLB; // distance lower bound
    int disUB; // distance upper bound

    // If a read has more duplicated base than this number, filter it out.
    int filteredDummyBases;
    int filteredRepeatBases;
    bool bFileterDummyRead;
    bool bFileterRepeatRead;
    char readtag_delimiter;
    // for test
    bool bTest;
};

class ParameterList : public MappingOpts
{
public:
    ParameterList(void) ;
    void setDefaults(void);
    bool checkRefValidity(void);
    bool truncatReadLength(void);
    void getOptsByCheckingExtName(void);

    bool validFlag;
    // Basic Input
    char refFile[FILENAME_MAX];
    char indexFileN[FILENAME_MAX];
    char readsFile[FILENAME_MAX];
    char seedName[FILENAME_MAX];
    string refFormat; // index, fasta, list
    int seedId;
    // Index
    bool bMakeIndex;                  // Default is false
    bool bSaveIndex;                  // Default is false
    // Reads files (can be selected by reads file)
    bool bMappedSOLiDRead;
    bool bMappedLongRead;
    char qualityFile[FILENAME_MAX];
    unsigned int truncatedReadLength;
    // others
    bool bMaskedMathRepeat;
};

ParameterList getParameterList(int argc, const char** argv);
unsigned int getReadLength(const char* readSetFileName, char expFileFormat = 'N');
unsigned int getAnchorLength(unsigned int readLength, unsigned int setAnchorLength);
bool retriveReadSetsAndSettings(ParameterList& P, vector<string>& readSetsList);
bool checkReadsSetNamesValidity(vector<string>& readSetsList);
bool getReadSetsFilenames(ParameterList &P, vector<string>& readSetList);
bool checkFileListHasTheRightExt(vector<string>& readSetList);
bool withSupportExtFileName(const char* fileName);
bool withFastaExtFileName(const char* fileName);
int selectSeed(ParameterList& P);
void printSynopsis(void);
void printUsageInfo(string helpOpt);

// Overwrite string if the source string is not null
inline bool setStr(char* str1, const char* str2)
{
    if (str2[0] != '\0') {
        strcpy(str1, str2);
        return(true);
    } else {
        return(false);
    }
}
#endif

